#include "log.hpp"
#include "Protool.hpp"
#include "TcpServer.hpp"
#include <memory>
#include "NetCal.hpp"

void Usage(std::string proc)
{
    std::cerr << "Usage:" << proc << " port" << std::endl;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }

    Enable_Console_log_Strategy();
    std::unique_ptr<Cal> cal = std::make_unique<Cal>();
    std::unique_ptr<Protocol> protocol = std::make_unique<Protocol>([&cal](Requst &req) -> Response
                                                                    { return cal->Execute(req); });

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(std::stoi(argv[1]), [&protocol](std::shared_ptr<Socket> &sock, InetAddr &client)
                                                                  { protocol->GetRequst(sock, client); });
    tsvr->Start();

    return 0;
}